//
//  BVCouponCell.m
//  BuyVegetable
//
//  Created by zhuzi on 16/10/18.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVCouponCell.h"

@implementation BVCouponCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.backgroundColor = [UIColor clearColor];
    self.BgImg = [[UIImageView alloc]init];
    [self.contentView addSubview:self.BgImg];
    self.BgImg.sd_layout
    .topSpaceToView(self.contentView,0)
    .bottomSpaceToView(self.contentView,0)
    .leftSpaceToView(self.contentView,0)
    .rightSpaceToView(self.contentView,0);
    
    self.ruleLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.ruleLabel];
    self.ruleLabel.font = [UIFont systemFontOfSize:18];
    self.ruleLabel.textColor = [UIColor BVTextGrayColor];
    self.ruleLabel.sd_layout
    .topSpaceToView(self.contentView,10)
    .leftSpaceToView(self.contentView,10)
    .autoHeightRatio(0);
    [self.ruleLabel setSingleLineAutoResizeWithMaxWidth:180];
    
    self.deadlineLabel = [[UILabel alloc]init];
    [self.contentView addSubview: self.deadlineLabel];
    self.deadlineLabel.font = [UIFont systemFontOfSize:15];
    self.deadlineLabel.textColor = [UIColor BVTextGrayColor];
    self.deadlineLabel.sd_layout
    .topSpaceToView(_ruleLabel,0)
    .leftSpaceToView(self.contentView,10)
    .autoHeightRatio(0);
    [self.deadlineLabel setSingleLineAutoResizeWithMaxWidth:200];
    
    self.limitLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.limitLabel];
    self.limitLabel.font = [UIFont systemFontOfSize:25];
    self.limitLabel.textColor = [UIColor whiteColor];
    self.limitLabel.sd_layout
    .topSpaceToView(self.contentView,10)
    .rightSpaceToView(self.contentView,10)
    .autoHeightRatio(0);
    [self.limitLabel setSingleLineAutoResizeWithMaxWidth:100];
    
    self.typeLbel = [[UILabel alloc]init];
    [self.contentView addSubview:_typeLbel];
    self.typeLbel.font = [UIFont systemFontOfSize:15];
    self.typeLbel.textColor = [UIColor whiteColor];
    self.typeLbel.sd_layout
    .topSpaceToView(self.limitLabel,0)
    .rightSpaceToView(self.contentView,10)
    .heightIs(40);
    [self.typeLbel setSingleLineAutoResizeWithMaxWidth:100];
    
    self.deleteButton = [[UIButton alloc]init];
    [self.contentView addSubview:self.deleteButton];
    [self.deleteButton setTitleColor:[UIColor BVBaseOrangeColor] forState:UIControlStateNormal];
    [self.deleteButton setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteButton addTarget:self action:@selector(onDeleteButtonClick) forControlEvents:UIControlEventTouchUpInside];
    self.deleteButton.titleLabel.font = [UIFont systemFontOfSize:15];
    self.deleteButton.sd_layout
    .bottomSpaceToView(self.contentView,15)
    .rightSpaceToView(self.contentView,10)
    .heightIs(20)
    .widthIs(40);
    
    self.typeImg = [[UIImageView alloc]init];
    self.typeImg.image = [UIImage imageNamed:@"couponSeal"];
    [self.contentView addSubview:self.typeImg];
    self.typeImg.sd_layout
    .topSpaceToView(self.contentView,10)
    .bottomSpaceToView(self.contentView,10)
    .rightSpaceToView(self.contentView,10)
    .widthEqualToHeight();
    
    self.contentView.userInteractionEnabled = YES;}
-(void)setMyCouponModel:(BVMyCouponModel *)myCouponModel{
    BVMyCouponModel *couponModel = myCouponModel;
    
    self.ruleLabel.text = [NSString stringWithFormat:@"满%@元可用",couponModel.condition];
    NSString *startTimer = [couponModel.start_time substringToIndex:10];
    NSString *endTime = [couponModel.end_time substringToIndex:10];
    self.deadlineLabel.text = [NSString stringWithFormat:@"使用期限：\n%@ 至 %@",startTimer,endTime];
    self.limitLabel.text = [NSString stringWithFormat:@"%@元",couponModel.money];
}

-(void)onDeleteButtonClick{
    
    if (self.delegate&&[self.delegate respondsToSelector:@selector(getIndex:)]) {
       [_delegate getIndex:self.indexPath];
    }
    NSLog(@"删除删除");
}
@end
